package com.zxw.user.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.common.web.annotation.InitUpdateInfo;
import com.zxw.user.api.DeptAPI;
import com.zxw.user.domain.dto.DeptDTO;
import com.zxw.user.domain.dto.DeptSelectDTO;
import com.zxw.user.domain.entity.Dept;
import com.zxw.user.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-03-10
 */
@Api(tags = "部门模块")
@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
public class DeptController implements DeptAPI {

    private final DeptService deptService;

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("部门列表")
    @GetMapping("/company-depts")
    public BaseRes<List<DeptDTO>> getAllByCompanyIdList( Dept dept) {
        List<DeptDTO> deptDTOList = deptService.getAllByCompanyIdList(dept);
        return BaseRes.ok(deptDTOList);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("下拉选择部门(tree-select)")
    @GetMapping("/select-depts")
    public BaseRes<List<DeptSelectDTO>> getDeptSelectList() {
        List<DeptSelectDTO> deptDTOList = deptService.getDeptSelectList();
        return BaseRes.ok(deptDTOList);
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("添加部门")
    @PostMapping("/add-dept")
    public BaseRes addDept(@RequestBody Dept dept) {
        deptService.add(dept);
        return BaseRes.okAdd();
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiImplicitParam(name = "ids", value = "主键id string : 格式 1,2,3 ", required = true)
    @ApiOperation("删除部门")
    @DeleteMapping("/delete/{ids}")
    public BaseRes delete(@PathVariable("ids")String ids) {
        deptService.delete(ids);
        return BaseRes.okDelete();
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("根据主键id修改部门")
    @PutMapping("/update")
    public BaseRes update(@RequestBody Dept dept) {
        deptService.update(dept);
        return BaseRes.okUpdate();
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiImplicitParam(name = "id", value = "主键id", required = true)
    @ApiOperation("根据主键id获取部门详情")
    @GetMapping("/select/{id}")
    public BaseRes<Dept> getById(@PathVariable("id") Long id) {
        Dept dept = deptService.getById(id);
        return BaseRes.ok(dept);
    }

}
